<template>
    <a-modal v-model:visible="visible" :closable="false" :width="800" :wrap-style="{ overflow: 'hidden' }"
        @ok="onClose">
        <a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
            <a-row :gutter="24">

                <a-col :span="16">
                    <a-form-item name="name">
                        <a-input v-model:value="searchFormState.name" placeholder="请输入检索条件" />
                    </a-form-item>
                </a-col>

                <a-col :span="8" class="text-right">
                    <a-button type="primary" @click="refresh(true)">查询</a-button>
                </a-col>
            </a-row>
        </a-form>
        <s-table rowKey="id" tableLayout="fixed" :row-selection="{
        type: 'radio',
        selectedRowKeys: selectedRowKeys, onChange: onSelectChange
    }" :size="5" :data="loadData" bordered :columns="columns" class="mb-2">
            <template #bodyCell="{ column, record, index }">
                <template v-if="column.key === 'index'">
                    {{ index + 1 }}
                </template>
                <template v-if="column.dataIndex === 'supplierEntity'">
                    <span>{{ record.supplierEntity == 1 ? record.companyName : record.name }}</span>
                </template>
            </template>
        </s-table>


    </a-modal>
</template>
<script setup>
import api from '@/api/base_data/supplierApi'
// import api from '@/api/contract/revenueContract/index'
import { ref } from 'vue';

const rowSelection = {
    onChange: (selectedRowKeys, selectedRows) => {
        console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
    },
    getCheckboxProps: record => ({
        disabled: record.name === 'Disabled User',
        // Column configuration not to be checked
        name: record.name,
    }),
}
const visible = ref(false)
const show = (contractId) => {
    
    visible.value = true
}

const searchFormState = ref({})

const loadData = (parameter) => {
    return api.getPage(Object.assign(parameter, searchFormState.value)).then((res) => {
        return res
    })
}

const selectedRowKeys = ref([])
const selectRecords = ref({})
const onSelectChange = (selectedKeys, selectedRows) => {
    selectedRowKeys.value = selectedKeys;
    selectRecords.value = selectedRows
    console.log('selectedRowKeys changed: ', selectedRowKeys);
}
const onselectRow = (columns, index) => {
    return {
        onClick: (event) => {
            console.log('onselectRow clicked', columns, index);
            // selectedRowKeys.value = [columns["id"]]
        },
    }
}


const emits = defineEmits(['onClose'])
const onClose = () => {
    visible.value = false;
    emits('onClose', selectRecords.value)
};
defineExpose({
    show
});
const refresh = () => {


}
const columns = [
    {
        title: '序号',
        dataIndex: 'index',
        key: "index",
        ellipsis: true,
        width: '50px',
        align: 'center'
    },
    {
        title: '供应商名称',
        dataIndex: 'supplierEntity',
        width: '120px',
        align: 'center',
        checked: true
    },
    {
        title: '平台名',
        dataIndex: 'platform',
        align: 'center',
        width: '120px'
    },
    {
        title: '负责人',
        dataIndex: 'head',
        align: 'center',
        width: '120px'
    },
    {
        title: '业务范围',
        dataIndex: 'mainRange',
        align: 'center',
        width: '120px'
    },

]

</script>